package comand;

import comand.calulator.Calc;
import comand.impl.*;

import java.util.Stack;

//invoker
public class Calcultor {

    public static Double total = (double) 0;
    private final Calc calc = new Calc();
    private final Stack<Command> commands = new Stack<>();
    private final Stack<Command> undo = new Stack<>();


    //恢复撤销
    public void redo() {
        System.out.print("恢复撤销：");
        commands.push(undo.pop()).execute();
    }

    //撤销
    public void undo() {
        System.out.print("撤销：");
        Command pop = commands.pop();
        undo.push(pop).deExecute();
    }

    @Deprecated
    public void compute(char operator, int value) {
        Command command = new DefaultCommand(calc, operator, value);
        command.execute();
        commands.push(command);
    }

    public void add(double value) {
        Command addCommand = new Add(value);
        addCommand.execute();
        commands.push(addCommand);
    }

    public void sub(double value) {
        Command sub = new Sub(value);
        sub.execute();
        commands.push(sub);
    }

    public void mutiply(double value) {
        Command muti = new Muti(value);
        muti.execute();
        commands.push(muti);
    }

    public void devide(double value) {
        Command devide = new Devide(value);
        devide.execute();
        commands.push(devide);
    }
}